import { Tooltip } from 'antd';
import _ from 'lodash';
import type { ArtColumn } from 'ali-react-table';
import styles from './index.less';

export interface INewArtColumnType extends ArtColumn {
  tooltip?: boolean;
}

export const tableColumns: INewArtColumnType[] = [
  {
    name: '序号',
    code: 'num',
    width: 60,
    align: 'center',
    lock: true,
    render: (value: any, row: any, index: number) => {
      return index + 1;
    },
  },
  {
    code: 'stationName',
    name: '交易单元',
    align: 'center',
    width: 140,
    lock: true,
    tooltip: true,
    // features: { autoRowSpan: true },
  },
  {
    code: 'schedulingName',
    name: '调度名称',
    align: 'center',
    width: 140,
    tooltip: true,
  },
  {
    code: 'stationCapacity',
    name: '装机容量(MW)',
    align: 'center',
    width: 80,
  },
  {
    code: 'stationTypeName',
    name: '发电类型',
    align: 'center',
    width: 80,
  },
  {
    code: 'groupCompanyName',
    name: '发电集团',
    align: 'center',
    width: 140,
    tooltip: true,
  },
  {
    code: 'forecastSystemProvider',
    name: '功率预测系统供应商',
    align: 'center',
    width: 140,
    tooltip: true,
  },
  {
    code: 'managerName',
    name: '场站联系人姓名',
    align: 'center',
    width: 80,
  },
  {
    code: 'managerMobile',
    name: '场站联系人电话',
    align: 'center',
    width: 100,
  },
  {
    code: 'isMatched',
    name: '是否大基地项目',
    align: 'center',
    width: 100,
    render: (value: any) => {
      return value === '1' ? '是' : '否';
    },
  },
  {
    code: 'registerName',
    name: '登记名称（电力业务许可证）',
    align: 'center',
    width: 100,
    tooltip: true,
  },
  {
    code: 'benchmarkPrice',
    name: '基数电价(元/MWh)',
    align: 'center',
    width: 100,
  },
  {
    code: 'subsidyPrice',
    name: '补贴电价(元/MWh)',
    align: 'center',
    width: 100,
  },
  {
    code: 'settlementCycleType',
    name: '结算周期',
    align: 'center',
    width: 160,
  },
  {
    code: 'stationAddress',
    name: '场站位置',
    align: 'center',
    width: 140,
    tooltip: true,
  },
  {
    code: 'longitude',
    name: '升压站经度',
    align: 'center',
    width: 80,
  },
  {
    code: 'latitude',
    name: '升压站纬度',
    align: 'center',
    width: 80,
  },
  {
    code: 'superiorStationName',
    name: '上级站节点名称',
    align: 'center',
    width: 80,
    tooltip: true,
  },
  {
    code: 'remark',
    name: '备注',
    align: 'center',
    width: 180,
    tooltip: true,
  },
];

export const getColumns = ({ edit, del }: any): ArtColumn[] => {
  const newTableColumns: ArtColumn[] = [];
  tableColumns.forEach((col) => {
    if (!_.isFunction(col.render)) {
      col.render = (value: any) => {
        const str = value || value === 0 ? value : '-';
        return col.tooltip && value ? (
          <Tooltip placement="top" title={str}>
            <div className={styles.textover}>{str}</div>
          </Tooltip>
        ) : (
          str
        );
      };
    }
    newTableColumns.push(col);
  });
  newTableColumns.push({
    name: '操作',
    code: 'operate',
    align: 'center',
    lock: true,
    width: 110,
    render: (value, record, rowIndex) => {
      return (
        <div style={{ display: 'flex', justifyContent: 'center' }}>
          <span
            key="delect"
            style={{
              borderRight: '1px solid var(--bd-a20)',
              paddingRight: '10px',
              height: '14px',
              display: 'flex',
              alignItems: 'center',
              color: 'var(--bd-primary)',
              cursor: 'pointer',
            }}
            onClick={() => del(record, rowIndex)}
          >
            删除
          </span>
          <span
            key="edit"
            style={{
              padding: '0 10px',
              height: '14px',
              display: 'flex',
              alignItems: 'center',
              color: 'var(--bd-primary)',
              cursor: 'pointer',
            }}
            onClick={() => edit(record, rowIndex)}
          >
            编辑
          </span>
        </div>
      );
    },
  });
  return newTableColumns;
};

export const isMatched = [
  {
    value: '1',
    label: '是',
  },
  {
    value: '0',
    label: '否',
  },
];
